package com.jason.bean.vo;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.jason.bean.Resource;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Menu extends Resource {
	private List<Menu> childMenus;
	private Menu parentMenu;

	public void addChildMenu(Resource resource) {
		Menu childMenu = toResourceForMenu(resource);
		if (childMenus == null) {
			childMenus = new ArrayList<>();
		}
		childMenu.parentMenu = this;
		if(childMenus.contains(childMenu)) {
			childMenus.remove(childMenu);
		}
		childMenus.add(childMenu);
	}
	@Override
	public boolean equals(Object obj) {
		return super.equals(obj);
	}
	
	public static Menu toResourceForMenu(Resource resource) {
		String json=JSONObject.toJSONString(resource);
		return JSONObject.parseObject(json, Menu.class);
	}
	@Override
	public String toString() {
		return "Menu [getId()="
				+ getId() + ", getName()=" + getName() + ", getUrl()=" + getUrl() + ", getPid()="
				+ getPid() + ", getBackup1()=" + getBackup1() + ", getBackup2()=" + getBackup2()
				+ ", getBackup3()=" + getBackup3() + ", getBackup4()=" + getBackup4()
				+ ", getBackup5()=" + getBackup5() + ", getCreateTime()=" + getCreateTime()
				+ ", getUpdateTime()=" + getUpdateTime() + ", getStatus()=" + getStatus()
				+ ", hashCode()=" + hashCode() + ", toString()=" + super.toString()
				+ ", getClass()=" + getClass() + "]";
	}
	
}
